import React from 'react'
import HTTP from '../../services/api'
import userApi from '../../api/user.api'
import { Avatar,Button } from 'antd'
function getUserToken(){
    let token = localStorage.getItem('token') || ''
    return token
}
function getUserinfo(){
    let userinfo = localStorage.getItem('userinfo')
    userinfo = JSON.parse(userinfo)
    return userinfo
}
export default class UserCenter extends React.Component{
    constructor(){
        super()
    }
    loginout = async()=>{
        let result = await HTTP({method:'get'},userApi.userLoginout,{type:'loginout'})
        localStorage.clear()
    }
    render(){
        if(getUserToken())
        {
            return(
                    <>
                    <Avatar size={48} src={getUserinfo()['header_img']} onClick={()=>{this.loginout()}} />
                    </>
            )
        }
        else {
            return (
               <Button>请登录</Button> 
            )
        }
    }
}

